$(document).ready(function(){
   //var vConsole = new VConsole();  //手机调试

    $.toast.prototype.defaults.duration=1600;

    console.log(window.location.href);


    OPENID      =  getUrlParam('openid');
    TERMINALID  =  getUrlParam('terminalid');
    SEXAREA     =  getUrlParam('sex');
    FLAG        =  getUrlParam('flag');//1 预约  2.非预约
    // DEALERNAME  =  decodeURI(getUrlParam("dealerName"), "utf-8");
    // TERMINALNAME=  getUrlParam('terminalName');



    var resMsg;
    $.showLoading("加载中...");
    $.ajax({
        type: 'GET',
        dataType: 'json',
        async:false,   //同步
        url: '../../../takeControles',
        data: {"terminalid":    TERMINALID,
            "openid":        OPENID,
            "timestamp":     "1000",
            "flag":          FLAG ,
            "sex":            SEXAREA ,
            "types": "loadHomePage"},
        contentType: 'application/x-www-form-urlencoded',
        success: function(res){
            console.log(res);
            if(res.err_code=='0'){
                resMsg=res;
                $.hideLoading();
            }else if(res.err_code=='8002'){
                resMsg='1';
                $.hideLoading();
                $('#takeAbnormal_img').addClass("abnormalImg");
                $("#takeAbnormal_img").attr("src","/htmlFive/common/images/tnlOffline.png");
                $('#takeAbnormal_font').addClass("offlineFont");
                $('#takeAbnormal_font_val').append("设备离线,请联系管理员或选择其他设备^_^");
                $("#takeAbnormal").css("display","flex");

            }else if(res.err_code =="-1"){
                $.hideLoading();
                resMsg='1';
                $('#takeAbnormal_img').addClass("abnormalImg");
                $("#takeAbnormal_img").attr("src","/htmlFive/common/images/tnlOffline.png");
                $('#takeAbnormal_font').addClass("offlineFont");
                $('#takeAbnormal_font_val').append("设备不存在,请联系管理员或选择其他设备^_^");

                $(".sele-case").css("display","none");
                $("#takeAbnormal").css("display","flex");
            }else{
                resMsg='1';
                $.toast('请求出错，请重试。');
            }
        }
    });
    if(resMsg=='1'){
        return;
    }
    var TAKELIST = resMsg.data.takeList;
    if(TAKELIST == undefined || TAKELIST.length ==0){
            $(".take-container").css("display","none");
            $('#takeAbnormal').css("display","flex");
            $('#takeAbnormal_img').addClass("abnormalImg");
            $("#takeAbnormal_img").attr("src","/htmlFive/common/images/noOrder.png");
            $('#takeAbnormal_font').addClass("noOrderFont");
            $('#takeAbnormal_font_val').append("无租用箱门，请点击'箱门租用'进行预约^_^");
     }else{//取列表不为空
        var remarkLength=resMsg.data.takeList[0].remark.length;
        if (remarkLength!=0 && FLAG==2) {//不等于0就是扫错了柜子 --> 区域提示regionTips
             var remarkNews=resMsg.data.takeList[0].remark;
             var html = '<div class="region-tips"><div class="region-box"><div class="current-region" style="text-align:center;"><img src="/htmlFive/common/images/tips.png" class="warn-pic">温馨提示： </div>  <div> <div>您在 <span class="store-region">'+remarkNews+'</span> 有存物订单，</div> <div>请前往 <span class="store-region">'+remarkNews+'</span> 进行扫码操作。</div>   </div> </div>  </div>';
             $('.take-list-box').html(html);
             $('.take-nav').html('取物开箱');
         } else {
            var storedlist = TAKELIST;
                storedlist.sort(compare('areacode')); //排序
                storedlist.sort(compare('boxname')); //排序
                //根据terminalid分类
                var arrt=JSON.parse(JSON.stringify(storedlist));
                var  className=keyword(arrt); //去重 分类条件
                //console.log(className);
                var classStr='';
                for (var i = 0; i <className.length; i++) {
                        classStr+='<div> <div class="take-type-name">'+className[i].areaname+' </div> <div class="detailslist" data-area="'+className[i].areacode+'"></div> </div>'
                }

                $('.take-list-box').html(classStr);

                $('.detailslist').each(function () {
                        var loopbox='';
                        var standard=$(this).attr('data-area'); //分类条件  areacode
                        for (var i = 0; i <storedlist.length ; i++) {
                            if(standard==storedlist[i].areacode){
                                //    loopbox+='<div class="take-list-item"><div class="take-body-left"><div class="cabinet-size">'+  storedlist[i].boxtypename+'箱</div><div class="take-list-number">箱号:  <span >' +   storedlist[i].boxname + '</span> </div></div><div class="take-body-right"><div data-boxname="' + storedlist[i].boxname + '" data-boxid="' + storedlist[i].boxid + '" data-tStoredtime="'+storedlist[i].storedtime+'"  data-packageid="' + storedlist[i].packageid + '" data-tradewaterno="' + storedlist[i].tradewaterno + '"  data-boxtypecode="' + storedlist[i].boxtypecode + '"   data-terminalid="' + storedlist[i].terminalid + '" class="take-open-btn">开箱</div></div><div class="tkae-code"><div class="get-code">二维码</div></div>   <div class="take-psd"><div class="psdbtn" class="psdbtn" data-tradewaterno="' + storedlist[i].tradewaterno + '"  >密码</div></div>    </div>';
                 loopbox+= '<div class="take-list-item">'
                            +  '<div class="take-body-top">'
                            +        '<div class="cabinet-size">'+  storedlist[i].boxtypename+'箱</div>'
                            +        '<div class="take-list-number">箱号:  <span >' +   storedlist[i].boxname + '</span> </div>'
                            +  ' </div>'
                            +  '<div class="take-body-bottom">'
                            +       '<div class="take-body-right">'
                            +           '<div data-boxname="' + storedlist[i].boxname + '" data-boxid="' + storedlist[i].boxid + '" data-tStoredtime="'+storedlist[i].storedtime+'"  data-packageid="' + storedlist[i].packageid + '" data-tradewaterno="' + storedlist[i].tradewaterno + '"  data-boxtypecode="' + storedlist[i].boxtypecode + '"   data-terminalid="' + storedlist[i].terminalid + '" class="take-open-btn">开箱</div>'
                            +       '</div>'
                            +       '<div class="take-psd">'
                            +            '<div class="psdbtn" class="psdbtn" data-tradewaterno="' + storedlist[i].tradewaterno + '"  >设置密码</div>'
                            +        '</div>'
                            +       '<div class="take-code">'
                            +           ' <div class="get-code">二维码</div>'
                            +       '</div>'
                            +   '</div>'
                            +'</div>'

                            }
                        }
                        $(this).html(loopbox);
                });

               if(false){  //是否显示设置密码按钮
                  $('.take-psd').css('display','none');
                  $('.take-open-btn').css('padding','0 0.5rem');
               }
            }//没有扫错柜子
    }//如果有箱子

    document.body.addEventListener('touchstart', function () { })//...空函数即可; 激活active

});




$('#takePsd').blur(function () {  //ios页面被顶上去下不来
    console.log('ios_input');
    var currentPosition,timer;
    var speed=1;//页面滚动距离
    timer=setInterval(function(){
        currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
        currentPosition-=speed;
        window.scrollTo(0,currentPosition);//页面向上滚动
        currentPosition+=speed; //speed变量
        window.scrollTo(0,currentPosition);//页面向下滚动
        clearInterval(timer);
    },1);

});



 window.onload = function () {

    var tboxid,ttradewaterno,tpackageid,tStoredtime,tboxtype,tStorenumber,makeuppayment;
    var opentype;        //开箱  补交类型  1：非补交开箱   2：补交开箱
    var failtype;       //报错  补交类型   1:存开箱失败     2:取开箱失败(非补交)  3:取开箱失败(补交)
    var userange;      //:  1 : 结束订单(一存一取 即 直接退柜)    2：继续续租(一存多取 即 临时取和退柜)
    var prepaymenttype;  //收费方式 0免费模式 1按小时收费    2按天收费  3按小时段收费
    var terminalid;
    var makeuptradewaterno; //补交订单号
    var premoneys;          //退款金额


    $(".get-code").click(function (e) {//生成开箱二维码
        $.showLoading("请稍等...");
        var takeOpen=$(e.currentTarget).parent().prev().prev().children().eq(0);
        var boxID=takeOpen.attr("data-boxid"),
            ttradewaterno=takeOpen.attr("data-tradewaterno"),
            boxTypeCode=takeOpen.attr("data-boxtypecode"),
            terminalidCode=takeOpen.attr("data-terminalid");


        var data={"terminalid":terminalidCode,
            "openid":           OPENID,
            "boxID":            boxID,
            "orderCode":        ttradewaterno, //唯一流水号
            "boxTypeCode":      boxTypeCode,
            "types":"getQrCode"};
        var url='/storeControles';

        function getQrCode(res){
            console.log(res);
            if(res.err_code=='0'){
                $.hideLoading();
                var url=res.data.data.qrCode,
                    strHeader=res.data.data.qrCodeInfo,
                    canDom=$('#canvas-code'),
                    imgDom=$('#img-code');
                $('#img-code').empty();
                $('#canvas-code').empty();
                qrCodeNext(url,strHeader,canDom,imgDom);

                $('#wblock').modal('show');
            }else{
                $.hideLoading();
                $.toast('对不起，请稍后再试','text');
            }
        }
        ajax(data,url,getQrCode,false);
    });

     var orderCode='';
     $('.psdbtn').click(function (e) { //设置密码
         console.log('设置密码');
         $('#psdModal').modal('show');
         orderCode=e.currentTarget.dataset.tradewaterno;
     });

     $('#submitPsd').click(function(){ //提交密码
         var takePsd=$('#takePsd').val();
         if(takePsd.length==0){
             $.toast('密码为空，请重新输入','text');
         }else if(!(/^[A-Za-z0-9]+$/.test(takePsd))){
             $('#takePsd').val('');
             $.toast('格式不正确，请重新输入','text');
         }else{
             $.showLoading("请稍等...");
             console.log(takePsd); //getPsd
             var data={
                     "takePsd": takePsd,
                     "orderCode":orderCode,
                     "types": "setPassword"};
             var url='/userTerminalsControles';
             function setPassword(res){
                 if(res.data.errorCode=='1'){
                     $.hideLoading();
                     $('#psdModal').modal('hide');
                     $.toast(res.data.errorDesc,'text');
                 }else{
                     $.hideLoading();
                     $('#psdModal').modal('hide');
                     $.toast('设置成功','success');
                     $('#takePsd').val('');
                 }
             }
             ajax(data,url,setPassword);
             // $.ajax({
             //     type: 'post',
             //     //async: false,                       // 同步加载
             //     dataType: 'json',
             //     url: '/userTerminalsControles',
             //     data:{
             //         "takePsd": takePsd,
             //         "orderCode":orderCode,
             //         "types": "setPassword"
             //     },
             //     success: function(res){
             //         console.log(res);
             //         if(res.data.errorCode=='1'){
             //             $.hideLoading();
             //             $('#psdModal').modal('hide');
             //             $.toast(res.data.errorDesc,'text');
             //         }else{
             //             $.hideLoading();
             //             $('#psdModal').modal('hide');
             //             $.toast('设置成功','success');
             //             $('#takePsd').val('');
             //         }
             //     }
             // })
         }
     });


    $(".take-open-btn").click(function (e) {  //点击按钮，获取开箱 信息
        $.showLoading("请稍等...");
         tboxtype=$(e.currentTarget).parent().prev().children(0).html(); //大小箱
         tboxid=$(e.currentTarget).attr("data-boxid");
         tStorenumber="0"+tboxid+"箱";
         ttradewaterno=$(e.currentTarget).attr("data-tradewaterno");
         tpackageid=$(e.currentTarget).attr("data-packageid");
         tStoredtime=$(e.currentTarget).attr("data-tStoredtime");  //存物时间
         terminalid=$(e.currentTarget).attr("data-terminalid");
        $(".take_box_type").html(tboxtype);
        $(".storage_start_time").html(tStoredtime); //开始存物时间

        var data={"terminalid":     terminalid,
                "boxid":          tboxid,
                "openid":         OPENID,
                "packageid":      ttradewaterno, //唯一流水号
                "tradewaterno":   ttradewaterno,
                "storedtime":     tStoredtime,
                "types":"queryCost"};
        var url='/takeControles';
        function queryCost(res){
            if(res.err_code=='0'){
                $.hideLoading();
                var opentime = res.data.taketime; //取物时间(服务器)
                var duration=intervalTime(tStoredtime,opentime);  // 获取存物时长
                makeuppayment=res.data.makeuppayment; //补缴金额
                prepaymenttype=res.data.prepaymenttype;
                premoneys=res.data.premoneys;
                $(".storage_end_time").html(res.data.taketime); //取物时间
                $(".storage_time").html(duration);  //时长
                $(".makeup-payment").html('￥'+returnFloat(makeuppayment));//补交金额
                $('.back-premoneys').html('￥'+returnFloat(premoneys));   //退款金额
                $('.modal-careful').html(res.data.remark);
                $(".take_box_number").html(res.data.boxname+'箱');
                if(res.data.openboxstatus==2){//openboxstatus --> 开箱状态     0:表示成功  1：表示失败   2:需要补交费用
                    opentype=2; //开箱  补交类型  1：非补交开箱   2：补交开箱
                    failtype=3; //报错  补交类型   1:存开箱失败     2:取开箱(非补交)  3:取开箱(补交);
                    makeuptradewaterno=res.data.makeuptradewaterno;  //补交订单号
                    userange=res.data.userange; //:  1 : 结束订单(一存一取 即 直接退柜) 2：继续续租(一存多取 即 临时取和退柜
                    $('#takePayModal').modal('show');  //支付弹出层
                }else{//不补交支付，直接去开箱
                    opentype=1;
                    failtype=2;
                    $('#takeOpenModal').modal('show');
                    if(res.data.userange=='1'){ //1   一存一取  控制是否存在临时取物按钮  2：一存多取 即 临时取和退柜
                        $("#takeOpenTemporary").css("cssText", "display:none !important"); //只有退柜按钮
                        $("#takeOpenForever").css({width:'100%',marginLeft:'0'});
                        userange=1;
                    }else{ //等于2的话用户可能会选择临时
                        userange=2;
                    }
                }
            }else{
                $.hideLoading();
                $.toast('请重试');
                console.log('获取信息失败');
            }
        }
        ajax(data,url,queryCost);
    });

    $("#takeOpenForever").click(function () { //退柜提醒
        $('#takeOpenModal').modal('hide');
        $('#takeRemindModal').modal('show');
        $('.RemindModalHeader').html('退柜提醒');
        $('#takeConfirm').html('确认退柜');
        $('#takeRemindModal .modal-body').html('请确认位置是否在当前柜，退柜后，结算费用并退回押金');
        userange=1;
    });

    $("#takeOpenTemporary").click(function () { //临时开箱提醒
        $('#takeOpenModal').modal('hide');
        $('#takeRemindModal').modal('show');
        $('#takeConfirm').html('确认开箱');
        $('.RemindModalHeader').html('临时开箱提醒');
        $('#takeRemindModal .modal-body').html('请确认位置是否在当前柜，临时开箱后，可以取物，存物操作');
        userange=2;
    });

    $("#takeGoPay").click(function(){  //补交支付
        $.ajax({
            type: 'POST',
            url: '/takeControles',
            //dataType: 'json',
            async:false,  //同步
            data: {
                "openid": OPENID,
                "terminalid": terminalid,
                "packageid": tpackageid,
                "tradewaterno":  tpackageid,
                "prepaymenttype": prepaymenttype,           //收费模式,
                "amount"  : makeuppayment,
                "types": "wxTakePay"
            },
            contentType: 'application/x-www-form-urlencoded',
            success: function (res) {
                if(res.length==0){
                    $.toast('支付失败,请重试！','text');
                }else{
                    var url="http://wcbt4.bjyada.com/merserwcbweb_t4/pay/index.do?qrCode="+encodeURIComponent(res.replace(/\s+/g,""));
                    console.log(url);
                    window.location.href=url;
                }
            },
            error: function () {
                console.log('error');
            }
        });

    });



//开箱并发起返回押金
    $("#takeConfirm").click(function(){
        $('#takeRemindModal').modal('hide');
        $('.modal-type').html(tStorenumber);
        $('.modal-number').html(tboxtype);
        $.showLoading("开箱中...");
            $.ajax({
                type: 'post',
                //async: false,                       // 同步加载
                dataType: 'json',
                url: '/takeControles',
                data:{"terminalid": terminalid,
                    "openid":     OPENID,
                    "boxid":      tboxid,
                    "packageid":  ttradewaterno,
                    "userange":   userange,  //1结束订单(一存一取即退柜)    2：继续续租(一存多取即临时开箱)
                    "opentype":   opentype, //   开箱类型   1：非补交开箱   2：补交开箱
                    "types": "takeOpenBoxs"},
                success: function(res){
                    console.log(res);
                    if(res.data.openboxstatus=='0') { //开箱成功
                        $.hideLoading();
                        if(userange==1){
                             refund();
                        }else{
                            $.toast('开箱成功');
                        }
                    }else if(res.data.openboxstatus=='1'){ //开箱失败
                        //进行三次循环 异常开箱
                        var i=0;
                        var endorderState;
                        var interval=setInterval(function(){
                            if(i>1){//最后一次循环
                                clearInterval(interval);
                                $.hideLoading();
                                $.modal({
                                    title: "开箱异常",
                                    text: "温馨提示：若箱门正常打开请选择“箱门已开”，若选择“箱门未开”，请尝试重新打开或联系管理员处理故障或退还押金",
                                    buttons:[
                                        { text: "箱门已开", onClick: function(){
                                            $.showLoading("加载中...");
                                            setTimeout(function () {
                                                if(userange==1){  //1结束订单(一存一取即退柜)    2：继续续租(一存多取即临时开箱)
                                                    endorderState=1;  //0:无效不处理  1:结束订单(前提是一存多取的情况)
                                                    var result = userOpenExcep(terminalid,tboxid,ttradewaterno,failtype,endorderState,1);
                                                    //  failtype 2 -取失败-非补交  3-取失败-补交
                                                    if(result.err_code=='0'){
                                                         refund();
                                                    }else{
                                                        $.alert("加载超时!");
                                                    }
                                                }else if(userange==2){
                                                    endorderState=0;
                                                    userOpenExcep(terminalid,tboxid,ttradewaterno,failtype,endorderState,1);
                                                    $.toast('箱门已开');

                                                }
                                            })

                                        }},
                                        { text: "箱门未开", className: "default", onClick: function(){
                                               // if(userange==1){endorderState=0;}else if(userange==2){ endorderState=0;  }
                                                endorderState=0;
                                                var result=userOpenExcep(terminalid,tboxid,ttradewaterno,failtype,endorderState,2);
                                                if(result.err_code==0){
                                                    console.log('箱门未开');
                                                    $.toast('开箱失败，请重试','text');
                                                    setTimeout(function () {
                                                        window.location.reload();
                                                    },1500)

                                                }else{
                                                    $.alert("加载超时!" );
                                                }
                                            }}
                                    ]
                                });
                            }else{ //第一次和第二次
                                i++;
                                console.log("第" + i + "次异常开箱");
                                var data={"terminalid": terminalid,
                                        "boxid":       tboxid,
                                        "openid":      OPENID,
                                        "packageid":   ttradewaterno,
                                        "openboxtype": 2,             //'1:存开箱  2:取开箱'
                                        "types": "abnormalOpenBox"};
                                var url='/userTerminalsControles';
                                function abnormalOpenBox(res){
                                    console.log("i:",i);
                                    if (res.err_code == '0') {
                                        $.hideLoading();
                                        $.toast('箱门已开');
                                        clearInterval(interval);

                                    }
                                }
                                ajax(data,url,abnormalOpenBox,false);
                            }
                        },2500);
                    }
                },
                error:function () {
                    console.log('错误');
                }
            })
    });

 function refund() {
     //退款，查询，更新订单， 查询以成功为主  //premoneys为0是不走退款，直接更新订单
    if(premoneys==0){ //不需退款
        update();
    }else{
        var res=refundRequest(); // 0 成功 1：失败 2：未知
        if(res==1){
          var res1=refundRequest();
          if(res1==1){
              refundRequest();
              refundSuccess();
          }else{
              refundSuccess();
          }
        }else{
            refundSuccess();
        }
    }
 }


 function  refundRequest() {
    var result;
     $.ajax({  //更新订单列表
         type: 'post',
         async: false,                       // 同步加载
         dataType: 'json',
         url: '/takeControles',
         data: {
             "openid": OPENID,
             "tradewaterno": tpackageid,   //订单号
             "refund_fee": premoneys,
             "types": "refund"
         },
         success: function (res) {
             result = res;
         },
         error: function () {
             console.log("refund:error")
         }
     });
     return result;
 }

 function refundSuccess() {
     $.showLoading("加载中...");
     setTimeout(function () {
         $.ajax({
             type: 'POST',
             url: '../../../storeControles',
             dataType: 'json',
             async: false,  //同步
             data: {
                 "orderNo": tpackageid,
                 "types": "queryPay"
             },
             contentType: 'application/x-www-form-urlencoded',
             success: function (res) {
                 alert('take queryPay'+res);
                 if(res == 1) {
                     $.showLoading("加载中...");
                     $.alert({
                         title: '退款失败，请重试',
                         text: '',
                         onOK: function () {
                             window.location.reload();
                         }
                     });
                 }else{
                     $.showLoading("加载中...");
                     update();
                 }
             },
             error: function () {
                 console.log("queryPay:error")
             }
         })
     },1000);
 }


function update(){
     var data={"terminalid": terminalid,
             "openid":     OPENID,
             "packageid":  ttradewaterno,   //订单号
             "types":      "updateOrderNew"};
     var url='/userTerminalsControles';
     function updateOrderNew(res){

         if (res.err_code == '0'){
             $.hideLoading();
             $('#takeEndModal').modal('show');
             $('.return-deposit').html('￥'+res.data.refundmoney/100);  //退款金额
             $('.take-end').click(function(){ window.location.reload();});
         }else{
             $.hideLoading();
             $.alert({
                 title: '退柜失败请重新尝试',
                 text: '',
                 onOK: function () {
                     window.location.reload();
                 }
             });
         }
     }
     ajax(data,url,updateOrderNew,false);
    // $.ajax({  //更新订单列表
    //     type: 'post',
    //     async: false,                       // 同步加载
    //     dataType: 'json',
    //     url: '/userTerminalsControles',
    //     data:{"terminalid": terminalid,
    //         "openid":     OPENID,
    //         "packageid":  ttradewaterno,   //订单号
    //         "types":      "updateOrderNew"},
    //     success: function(res){
    //         alert('take update'+res.err_code);
    //         if (res.err_code == '0'){
    //             $.hideLoading();
    //             $('#takeEndModal').modal('show');
    //             $('.return-deposit').html('￥'+res.data.refundmoney/100);  //退款金额
    //             $('.take-end').click(function(){ window.location.reload();});
    //         }else{
    //             $.hideLoading();
    //             $.alert({
    //                 title: '退柜失败请重新尝试',
    //                 text: '',
    //                 onOK: function () {
    //                     window.location.reload();
    //                 }
    //             });
    //         }
    //     }
    // });
}



 $('.goRetreat').click(function () { //订单记录页面
       //console.log(OPENID);
       window.location.href="/storeControles?types=orderQuery"+"&openid="+OPENID+"&currentpage="+1+"&pagemumber=20";
 });





};



function returnFloat(value){ //格式化金额
    var value=Math.round(parseFloat(value))/100;
    var xsd=value.toString().split(".");
    if(xsd.length==1){
        value=value.toString()+".00";
        return value;
    }
    if(xsd.length>1){
        if(xsd[1].length<2){
            value=value.toString()+"0";
        }
        return value;
    }
}


function intervalTime (startTime, endTime){//格式：2019-12-12 12:12:12
    var startTime1=startTime.replace(/\-/g, "/");
    var endTime1=endTime.replace(/\-/g, "/");

    var date1 = new Date(startTime1);  //开始时间
    var date2 = new Date(endTime1);    //结束时间
    var date3 = date2.getTime() - date1.getTime();  //时间差的毫秒数
    //计算出相差天数
    var days = Math.floor(date3 / (24 * 3600 * 1000));
    //计算出小时数

    var leave1 = date3 % (24 * 3600 * 1000);    //计算天数后剩余的毫秒数
    var hours = Math.floor(leave1 / (3600 * 1000));
    //计算相差分钟数
    var leave2 = leave1 % (3600 * 1000);        //计算小时数后剩余的毫秒数
    var minutes = Math.floor(leave2 / (60 * 1000));

    //计算相差秒数
    var leave3 = leave2 % (60 * 1000);      //计算分钟数后剩余的毫秒数
    var seconds = Math.round(leave3 / 1000);
    //console.log(" 用时： " + days + "天 " + hours + "小时 " + minutes + " 分钟" + seconds + " 秒");
    // console.log(days,hours,minutes);
    if(days==0){
        return hours + "小时 " + minutes + " 分钟"
    }else{
        return days + "天 " + hours + "小时 " + minutes + " 分钟"
    }
}


if(window.name != 'take'){  //返回刷新
    window.location.reload();
    window.name = 'take';
}else{
    window.name = '';
}




/*Swiper顶部广告样式控制 !*/
var mySwiper = new Swiper ('#top_ad',{
    loop: true, // 循环模式选项
    autoplay: true,
    pagination: {
        el: '.swiper-pagination',
        hideOnClick :true,
        renderBullet: function (index, className) {
            return '<span class="' + className + '"></span>';
        },
    },
});


/* Swiper页面底部存取菜单按钮触发动作 */
var STmodalChoose = new Swiper('#STmodalChoose');

// $('#btn_store').click(throttle(btnStore));
// $('#btn_take').click(throttleTake(btnTake));

var flag=getUrlParam('flag');
//console.log(flag);
if(flag==1){//预约

    $('#btn_store').click(de(btnStores));
    // $('#btn_take').click(throttle(btnTakes));
    $('#btn_take').click(function(){self.location.reload()});

}else if(flag==2){//非预约

    $('#btn_store').click(de(btnStore));
    // $('#btn_take').click(throttle(btnTake));
    $('#btn_take').click(function(){self.location.reload()});
}